package com.rw.tool.util.expression.expression.parser.element;

import com.rw.tool.util.expression.element.Calculation;
import com.rw.tool.util.expression.element.ExpressionElement;
import com.rw.tool.util.expression.expression.Expression;
import com.rw.tool.util.string.StringScanner;

import java.util.Optional;

/**
 * 处理计算符号
 */
public class CalculationElementParser extends ElementParser<Calculation> {
    public CalculationElementParser() {
        super(Calculation.class);
    }

    @Override
    public Optional<ExpressionElement> handler(StringScanner scanner, int scale) {
        // 如果当前状态能接受计算符号，则扫描计算符号
        if (scanner.hasNext(Expression.CALCULATION_REGEX)) {
            return Optional.of(Calculation.of(scanner.next(Expression.CALCULATION_REGEX)));
        }

        return Optional.empty();
    }
}
